package com.shanzmoo.admin.web.product;


import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.core.cache.CurrentUserCache;
import com.shanzmoo.db.product.entity.ProductBrandEntity;
import com.shanzmoo.db.product.entity.vo.BrandQueryVO;
import com.shanzmoo.db.product.service.IProductBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <p>
 * 商品品牌 前端控制器
 * </p>
 *
 * @author Xueqz
 * @since 2020-12-06
 */
@Api(tags = "商品-商品品牌")
@RestController
@RequestMapping("/api/product/brand")
public class ProductBrandController {

    @Autowired
    private IProductBrandService productBrandService;

    @ApiOperation(value = "商品品牌list")
    @GetMapping("/brandList")
    public SHttpResponse<PageRespBase<ProductBrandEntity>> brandList(BrandQueryVO brandQueryVO) {
        SResponse<PageRespBase<ProductBrandEntity>> re = productBrandService.getBrandList(brandQueryVO);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "添加商品品牌")
    @GetMapping("/addBrand")
    public SHttpResponse<Boolean> brandList(ProductBrandEntity productBrandEntity) {

        productBrandEntity.setCreateUser(CurrentUserCache.getUserId());
        productBrandService.save(productBrandEntity);

        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "删除商品品牌")
    @GetMapping("/delBrandById")
    public SHttpResponse<Boolean> delBrandById(@RequestParam(value = "brandId") Integer brandId) {
        ProductBrandEntity productBrandEntity = new ProductBrandEntity();
        productBrandEntity.setId(brandId);
        productBrandEntity.setUpdateUser(CurrentUserCache.getUserId());
        productBrandEntity.setCreateTime(LocalDateTime.now());
        productBrandEntity.setDeleted(true);

        productBrandService.save(productBrandEntity);
        return SHttpResponse.ok(Boolean.TRUE);
    }
}
